package com.yxy.mapper;

import com.github.pagehelper.Page;
import com.yxy.pojo.dto.SightsBookingPageQueryDTO;
import com.yxy.pojo.entity.BookingPerson;
import com.yxy.pojo.entity.SightsBooking;
import com.yxy.pojo.vo.SightsBookingPageQueryVO;
import com.yxy.pojo.vo.SightsBookingVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SightsBookingMapper {
    /**
     * 添加
     * @param sightsBooking
     */
    void add(SightsBooking sightsBooking);

    /**
     * 添加预约人信息
     * @param build
     */
    void addBookingPerson(BookingPerson build);

    /**
     * 根据sightId和userId查询
     * @param sightsId
     * @param userId
     * @return
     */
    @Select("select * from sights_booking where sights_id = #{sightsId} and user_id = #{userId}")
    List<SightsBooking> selectBySightsIdAndUserId(Integer sightsId, Integer userId);

    /**
     * 修改状态
     * @param sightsBooking
     */
    @Update("update sights_booking set status = #{status} where id = #{id} and sights_id = #{sightsId} and user_id = #{userId}")
    void updateStatus(SightsBooking sightsBooking);

    /**
     * 根据id删除预约人信息
     * @param id
     */
    @Delete("delete from booking_person where booking_id = #{id}")
    void deleteBookingPersonBySightsBookingId(int id);

    /**
     * 分页查询
     * @param sightsBookingPageQueryDTO
     * @return
     */
    Page<SightsBookingPageQueryVO> pageQuery(SightsBookingPageQueryDTO sightsBookingPageQueryDTO);

    /**
     * 根据id查询预约人信息
     * @param id
     * @return
     */
    @Select("select * from booking_person where booking_id = #{id}")
    List<BookingPerson> selectBookingPersonListBySightsBookingId(int id);

    /**
     * 查询所有
     * @return
     */
    @Select("select * from sights_booking")
    List<Integer> getAll();

    /**
     * 分页查询
     * @param sightsBookingPageQueryDTO
     * @return
     */
    @Select("select * from sights_booking where user_id = #{userId} and status = #{status}")
    Page<SightsBookingPageQueryVO> pageQuerySightsBooking(SightsBookingPageQueryDTO sightsBookingPageQueryDTO);

    /**
     *  根据id查询
     * @param id
     * @return
     */
    @Select("select * from sights_booking where id = #{id}")
    SightsBooking selectById(Integer id);

    /**
     * 修改
     * @param sightsBooking
     */
    void update(SightsBooking sightsBooking);

    /**
     * 查询所有
     * @return
     */
    @Select("select s.*, u.name from sights_booking s left join user u on s.user_id = u.id")
    List<SightsBookingPageQueryVO> selectList();
}
